﻿// <copyright file="NotificationsGM.cs" company="Gravity Age Studios">
// Code released under the MIT license (see License.txt).
// </copyright>
// <author>Vicente Cartas Espinel</author>
// <email>vicente.cartas@gmail.com</email>
namespace LightSwitchApplication
{
    using System;
    using System.Windows.Controls;
    using Microsoft.LightSwitch.Presentation;
    using Microsoft.LightSwitch.Presentation.Extensions;

    public partial class NotificationsGM
    {
        #region Add Notification

        partial void AddNotification_Execute()
        {
            var notification = this.Collection.AddNew();
            notification.Read = false;
            notification.SentDate = DateTime.Now;

            this.FindControl("ModalAddNotification").DisplayName = "Add new Notification";
            this.OpenModalWindow("ModalAddNotification");
        }

        partial void SubmitAddNotification_Execute()
        {
            this.CloseModalWindow("ModalAddNotification");
        }

        partial void CancelAddNotification_Execute()
        {
            this.CloseModalWindow("ModalAddNotification");
            this.Collection.SelectedItem.Details.DiscardChanges();
        }

        #endregion

        #region View Notification

        partial void ViewNotification_CanExecute(ref bool result)
        {
            result = this.Collection.SelectedItem != null;
        }

        partial void ViewNotification_Execute()
        {
            this.FindControl("ModalViewNotification").DisplayName = "View Notification";
            this.OpenModalWindow("ModalViewNotification");
        }

        partial void SubmitViewNotification_Execute()
        {
            this.CloseModalWindow("ModalViewNotification");
        }

        #endregion
    }
}
